// packageE/memberasset/memberasset.js
const app = getApp()
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    },
    member_item: {
      type: null,
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    name_of_withdrawal: "",
    TemplateArray: []
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      this.customizeIncome();
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    //自定义提现收入语言
    customizeIncome() {
      try {
        var value = wx.getStorageSync("mailLanguage");
        if (value) {
          let mailLanguage = JSON.parse(value);
          // Do something with return value
          this.setData({
            name_of_withdrawal: mailLanguage.income.name_of_withdrawal,
          });
        }
      } catch (e) {
        // Do something when catch error
      }
    },
    Integral_love: function () {
      wx.navigateTo({
        url: "/packageB/member/Integral_love/Integral_love",
      });
    },
    //跳到爱心兑换值
    golove_index: function () {
      //love_index
      wx.navigateTo({
        url: "/packageB/member/love/Love_index/Love_index",
      });
    },
    gobalance: function () {
      //balance
      wx.navigateTo({
        url: "/packageA/member/balance/balance/balance",
      });
    },
    gointegral_v2: function () {
      //integral_v2
      wx.navigateTo({
        url: "/packageB/member/integral/integral",
      });
    },
    goextension: function () {
      //extension
      // wx.navigateTo({
      //   url: "/packageG/pages/member/extension/extension",
      // });
      this.getTemplate()
    },
    getTemplate: function() {
      let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
      app._getNetWork({
        url: urlStr,
        data: {
          small_type: 3,
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            let array = [];
            for (let i = 0; i < res.data.length; i++) {
              array.push(res.data[i].template_id);
            }
            this.setData({
              TemplateArray: array,
            });
            wx.requestSubscribeMessage({
              tmplIds: this.data.TemplateArray,
              success: (res) => {
                this.gotoIncome();
              },
              fail: (err) => {
                console.log(err);
                this.gotoIncome();
              },
            });
          } else {
            wx.showToast({
              title: res.msg,
              icon: "none",
              duration: 1500,
            });
          }
        },
        fail: (res) => {
          console.log(res);
        },
      });
    },
    // 验证手机身份
    gotoIncome: function() {
      let urlStr = app.getNetAddresss("member.member.withdrawByMobile");
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            // 商城--交易设置--开启提现绑定手机号，小程序端提现没有触发绑定手机号  任务编号51955
            if (res.data.is_bind_mobile == 1) {
              wx.navigateTo({
                url: "/packageA/member/withdrawEditmobile/withdrawEditmobile",
              });
              // withdrawEditmobile
            } else {
              wx.navigateTo({
                url: "/packageA/member/withdrawal/withdrawal",
              });
              // withdrawal
            }
          } else {
            wx.showToast({
              icon: "none",
              title: res.msg,
              duration: 1500,
            });
          }
        },
        fail: (res) => {
          console.log(res.msg);
        },
      });
    },
    CardIndexPage(){
      wx.navigateTo({
        url: "/packageB/member/CardIndex/CardIndex",
      });
    },
  },
});
